package egs;


/*Multilevel in heritance example 1 : */


/* 
class student
{
    int rollno;
    String name;
 
    student(int r, String n)
    {
        rollno = r;
        name = n;
    }
    void dispdatas()
    {
        System.out.println("Rollno = " + rollno);
        System.out.println("Name = " + name);
    }
}
 
class marks extends student
{
    int total;
    marks(int r, String n, int t)
    {
        super(r,n);   //call super class (student) constructor
        total = t;
    }
    void dispdatam()
    {
        dispdatas();    // call dispdatap of student class
        System.out.println("Total = " + total);
    }
}
 
class percentage extends marks
{
    int per;
     
    percentage(int r, String n, int t, int p)
    {
        super(r,n,t);  //call super class(marks) constructor
        per = p;
    }
    void dispdatap()
    {
        dispdatam();    // call dispdatap of marks class
        System.out.println("Percentage = " + per);
    }
}
public class multiInherit
{
    public static void main(String args[])
    {
        percentage stu = new percentage(1912, "SAM", 350, 50); //call constructor percentage
        stu.dispdatap();  // call dispdatap of percentage class
    
    	}
}*/

/*When a class hierarchy is created, in what order are the constructors for the classes that
make up the hierarchy called?
- See more at: http://www.java2all.com/1/1/11/55/Technology/CORE-JAVA/Inheritance/Multilevel-Inheritance#sthash.YNGErz1b.dpuf


Answer-------------
*/


class X
{
    X()
    {
        System.out.println("Inside X's constructor.");
    }
    public void disp(){
    	System.out.println("in X");
    }
}
 
class Y extends X   // Create a subclass by extending class A.
{
    Y()
    {
        System.out.println("Inside Y's constructor.");
    }
}
 
class Z extends Y   // Create another subclass by extending B.
{
    Z()
    {
        System.out.println("Inside Z's constructor.");
    }
}
 
public class multiInherit
{
    public static void main(String args[])
    {
      Z z = new Z();// calls constructors 
    	z.disp();
    	
    }
}
// output : the constructors are called in order of derivation.